package com.example.manager.service.impl;


import com.example.manager.mapper.UserMapper;
import com.example.manager.service.UserService;
import com.example.manager.domain.User;
import com.example.manager.pojo.Code;
import com.example.manager.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Result login(String username, String password) {
        if ("".equals(username) || "".equals(password)) {
            return new Result(Code.RESPONSE_CODE_FAIL, "用户名或密码为空");
        }
        User user = userMapper.selectUserByUserName(username);
        if (user == null) {
            return new Result(Code.RESPONSE_CODE_FAIL, "没有该用户");
        }
        if (!user.getPassword().equals(password)) {
            return new Result(Code.RESPONSE_CODE_FAIL, "密码错误");
        }
        if (user.getIdentity() != 1) {
            return new Result(Code.RESPONSE_CODE_FAIL, "您没有权限");
        }
        return new Result(Code.RESPONSE_CODE_SUCCESS, "登录成功");
    }
}
